package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;

public class PROPER extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    Object localObject = paramArrayOfObject[0];
    if (localObject != null)
    {
      StringBuffer localStringBuffer = new StringBuffer();
      String str = "" + localObject;
      int i = 0;
      for (int j = 0; j < str.length(); ++j)
      {
        char c = str.charAt(j);
        if (i == 32)
          localStringBuffer.append(Character.toUpperCase(c));
        else
          localStringBuffer.append(Character.toLowerCase(c));
        i = c;
      }
      return localStringBuffer.toString();
    }
    return localObject;
  }

  public Function.Type getType()
  {
    return Function.TEXT;
  }

  public String getCN()
  {
    return "PROPER(text): 将文本中的第一个字母和所有非字母字符后的第一个字母转化成大写，其他字母变为小写。\nText:需要转化为文本的公式、由双引号引用的文本串或是单元格引用。\n示例:\nPROPER(\"Finemore Integrated Office\")等于“Finemore Integrated Office”。\nPROPER(\"100 percent\")等于“100 Percent”。\nPROPER(\"SpreaDSheEt\")等于“Spreadsheet”。";
  }

  public String getEN()
  {
    return "PROPER(text): Capitalizes the first letter in a text string and any other letters in text that follow any character other than a letter. Converts all other letters to lowercase letters.\nText is text enclosed in quotation marks, a formula that returns text, or a reference to a cell containing the text you want to partially capitalize.\n\nExample:\n   PROPER(\"Finemore Integrated Office\") = \"Finemore Integrated Office\"\n   PROPER(\"100 percent\") = \"100 Percent\"\n   PROPER(\"SpreaDSheEt\") = \"Spreadsheet\"";
  }
}